# Purpose: Optional utility functions for the MCP client.
# Changes:
# - Corrected 'types' import from 'mcp'.
# - Removed import of non-existent 'mcp.protocol'.

import logging
from typing import Any, Dict

# Import MCP types from the 'mcp' package
try:
    from mcp import types as mcp_types
    # Import ClientSession for type hinting if needed here
    # from mcp import ClientSession
except ImportError:
     logging.warning("Could not import types from mcp package. Client utils may be limited.")
     mcp_types = None # Placeholder
     # ClientSession = Any # Placeholder

# Use core logger setup
from ..core.logging_setup import get_logger
logger = get_logger(__name__)


# Example utility remains commented out as it depends on specific session usage pattern
# async def call_tool_with_logging(session: ClientSession, tool_name: str, arguments: Dict[str, Any]) -> Any:
#     """Calls an MCP tool and logs the request and response."""
#     logger.info(f"Calling MCP Tool '{tool_name}' with args: {arguments}")
#     try:
#         result = await session.call_tool(tool_name=tool_name, arguments=arguments)
#         log_result = result
#         if isinstance(result, bytes): log_result = f"<bytes len={len(result)}>"
#         elif isinstance(result, (str, list, dict)) and len(str(result)) > 300:
#              log_result = repr(result)[:300] + "..."
#         logger.info(f"MCP Tool '{tool_name}' returned type {type(result).__name__}: {log_result}")
#         return result
#     except AttributeError as e: # If SDK types weren't imported
#          logger.error(f"AttributeError (likely missing mcp types) calling tool '{tool_name}': {e}", exc_info=True)
#          raise MCPClientError(f"Error calling tool '{tool_name}': {e}") from e
#     except mcp_types.RPCError as e: # Check if mcp_types was imported successfully
#          logger.error(f"RPCError calling MCP Tool '{tool_name}': Code={e.code}, Message={e.message}, Data={e.data}")
#          raise # Re-raise RPCError for caller to handle
#     except Exception as e:
#          logger.error(f"Unexpected error calling MCP Tool '{tool_name}': {e}", exc_info=True)
#          raise MCPClientError(f"Error calling tool '{tool_name}': {e}") from e